package com.cor_cloud.springbootliteflowdemo.controller;

import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.flow.LiteflowResponse;
import com.yomahub.liteflow.slot.DefaultContext;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author huhao
 */
@RestController
@RequestMapping("/liteflow")
public class TestController {

    @Resource
    private FlowExecutor flowExecutor;

    @GetMapping("/chain1")
    public String test1() {
        LiteflowResponse liteflowResponse = flowExecutor.execute2Resp("chain1", "arg", DefaultContext.class);

        // 构建返回值
        return liteflowResponse.isSuccess() ? liteflowResponse.getCode() : liteflowResponse.getMessage();
    }

    @GetMapping("/chain2")
    public String test2() {
        return flowExecutor.execute2Resp("chain2", "arg").getCode();
    }
}
